from manim import *

config.media_width = "75%"
config.verbosity = "WARNING"
config.tex_template = TexTemplateLibrary.ctex
config.background_color = GREY
# %%manim -qm RandomNumbers 
import random 

HOME='../assets/Images'
HOME2='../assets/SVG_Images'


class RandomNumbers(Scene):
    def construct(self):
        numbers = VGroup()
        for x in range(28):
            num = DecimalNumber()
            numbers.add(num)

        def randomize_numbers(numbers):
            for num in numbers:
                value = random.uniform(0,1)
                num.set_value(value)
                num.set_color(GREEN if value>.1 else RED)


        randomize_numbers(numbers)
        numbers.set(width=.38)
        numbers.arrange(RIGHT, buff=.1)
        numbers.to_edge(UR)

        def get_results(numbers):
            results = VGroup()
            for num in numbers:
                if num.get_value() > .1:
                    result = (
                        SVGMobject(f'{HOME2}/green_tick.svg')
                        .set_color(GREEN_C)
                        .set(width=.3)
                    )
                else:
                    result = (
                        SVGMobject(f'{HOME2}/cross.svg')
                        .set_color(RED_C)
                        .set(width=.3)
                    )
                result.next_to(num, DOWN, buff=.2)
                results.add(result)
            return results
        for k in range(10):
            self.play(UpdateFromFunc(numbers, randomize_numbers))
            self.wait()
            result = get_results(numbers)
            self.play(Write(result))
            self.wait()
            box = SurroundingRectangle(result)
            self.play(Create(box))
            self.play(FadeOut(box), FadeOut(result))
        self.wait()
